<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增鉴定报告')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: summernote-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-report-add">
        <h4 class="form-header h4">关联案件</h4>
        <input id="registerId" name="registerId" class="form-control" type="hidden">
        <!--审核状态 1:未通过 3:待审核 5:通过-->
        <input name="status" value="3" type="hidden">
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">送鉴单位：</label>
                    <div class="col-sm-8">
                        <input id="sendUnitId" readonly placeholder="请选择关联案件" onclick="selectReportToRegister()"
                               class="form-control" type="text" required>
                    </div>
                </div>
            </div>

            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">来文文号：</label>
                    <div class="col-sm-8">
                        <input id="documentNum" readonly class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">样本类别：</label>
                    <div class="col-sm-8">
                        <input id="category" class="form-control" type="text" readonly required>
                    </div>
                </div>
            </div>
<!--            <div class="col-sm-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label is-required">审核人员：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input id="auditorId" name="auditorId" class="hidden">-->
<!--                        <input id="auditor" name="auditor" readonly placeholder="请选择审核人员" onclick="selectAuditor()"-->
<!--                               class="form-control" type="text" required>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
        </div>


        <h4 class="form-header h4">出版单位意见</h4>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">出版单位意见：</label>
                    <div class="col-sm-10">

                        <input name="publishOps" style="visibility: hidden;" >
                        <div class="file-loading">
                            <input class="form-control file-upload" multiple id="publishOps" name="file" type="file" >
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-10">
                        <button type="button" class="btn btn-w-m btn-warning" onclick="photograph('publishOps')">
                            <i class="fa fa-check"></i>拍照
                        </button>
                    </div>
                </div>
            </div>
        </div>


        <h4 class="form-header h4">鉴定结论</h4>


        <div class="row">

            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">鉴定结论：</label>
                    <div class="col-sm-8">
                        <select id="appraCon" name="appraCon" class="form-control"
                                th:with="type=${@dict.getType('id_report_conclusion')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>

                        </select>
                    </div>
                </div>
            </div>
        </div>

        <div id="ChangeContent"></div>

        <h4 class="form-header h4">关联样本</h4>
        <div class="row">
            <div class="col-sm-6">
                <button type="button" class="btn btn-w-m btn-primary" onclick="selectReportToSample()">关联样本</button>
            </div>
            <div class="col-sm-6">
                <input class="form-control " id="sampleIds" name="sampleIds" style="visibility: hidden;" required>
            </div>
        </div>


        <!--            <div class="form-group">-->
        <!--                <label class="col-sm-3 control-label">关联样本：</label>-->
        <!--                <div class="col-sm-8">-->
        <!--                    <textarea name="sampleIds" class="form-control"></textarea>-->
        <!--                </div>-->
        <!--            </div>-->


        <div id="samples">

        </div>


        <div class="row">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i
                        class="fa fa-check"></i>保 存
                </button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i
                        class="fa fa-reply-all"></i>关 闭
                </button>
            </div>
        </div>


    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: summernote-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<!--模板JS引入-->
<script th:src="@{/ajax/libs/template/template.js}"></script>
<!--拍照预览图片模板-->
<script type="text/html" id="template">
    <div class="file-preview-frame krajee-default  kv-preview-thumb file-preview-success"
         id={{id}} data-fileindex="0" data-fileid={{title}} data-template="image">
        <div class="kv-file-content">
            <img src={{src}} class="file-preview-image kv-preview-data" title={{title}}
                 style="width:213px;height:160px;" alt={{title}}>
        </div>
        <div class="file-thumbnail-footer">
            <div class="file-footer-caption" title={{title}}>
                <div class="file-caption-info">{{title}}</div>
                <div class="file-size-info"><samp>(108.21 KB)</samp></div>
            </div>
            <div class="file-thumb-progress kv-hidden" style="display: block;">
                <div class="progress">
                    <div class="progress-bar bg-success progress-bar-success" role="progressbar" aria-valuenow="100"
                         aria-valuemin="0" aria-valuemax="100" style="width:100%;">
                        完成
                    </div>
                </div>
            </div>
            <div class="file-upload-indicator" title="上传"><i class="glyphicon glyphicon-ok-sign text-success"></i></div>
            <div class="file-actions">
                <div class="file-footer-buttons">
                    <button type="button" class="kv-file-upload btn btn-sm btn-kv btn-default btn-outline-secondary"
                            title="上传文件" style="display: none;"><i class="glyphicon glyphicon-upload"></i></button>
                    <button type="button" class="kv-file-remove btn btn-sm btn-kv btn-default btn-outline-secondary"
                            title="删除文件"><i class="glyphicon glyphicon-trash"></i></button>
                    <!--<button type="button" class="kv-file-zoom btn btn-sm btn-kv btn-default btn-outline-secondary" title="查看详情" id="show" onclick="showImg(this)"><i class="glyphicon glyphicon-zoom-in"></i></button>-->
                    <button type="button" class="kv-file-down btn btn-sm btn-default" title="下载附件"><i
                            class="fa fa-cloud-download"></i></button>
                </div>
            </div>

            <div class="clearfix"></div>
        </div>
    </div>
</script>

<script type="text/html" id="template1">
    <div class="file-preview-frame krajee-default  kv-preview-thumb file-preview-success"
         id={{id}} data-fileindex="0" data-fileid={{title}} data-template="image">
        <div class="kv-file-content">
            <img src={{src}} class="file-preview-image kv-preview-data" title={{title}}
                 style="width:213px;height:160px;" alt={{title}}>
        </div>
        <div class="file-thumbnail-footer">
            <div class="file-footer-caption" title={{title}}>
                <div class="file-caption-info">{{title}}</div>
                <div class="file-size-info"><samp>(108.21 KB)</samp></div>
            </div>
            <div class="file-thumb-progress kv-hidden" style="display: block;">
                <div class="progress">
                    <div class="progress-bar bg-success progress-bar-success" role="progressbar" aria-valuenow="100"
                         aria-valuemin="0" aria-valuemax="100" style="width:100%;">
                        完成
                    </div>
                </div>
            </div>
            <div class="file-upload-indicator" title="上传"><i class="glyphicon glyphicon-ok-sign text-success"></i></div>
            <div class="file-actions">
                <div class="file-footer-buttons">
                    <button type="button" class="kv-file-upload btn btn-sm btn-kv btn-default btn-outline-secondary"
                            title="上传文件" style="display: none;"><i class="glyphicon glyphicon-upload"></i></button>
                    <button type="button" class="kv-file-remove btn btn-sm btn-kv btn-default btn-outline-secondary"
                            title="删除文件"><i class="glyphicon glyphicon-trash"></i></button>
                    <!--<button type="button" class="kv-file-zoom btn btn-sm btn-kv btn-default btn-outline-secondary" title="查看详情" id="show" onclick="showImg(this)"><i class="glyphicon glyphicon-zoom-in"></i></button>-->
                    <button type="button" class="kv-file-down btn btn-sm btn-default" title="下载附件"><i
                            class="fa fa-cloud-download"></i></button>
                </div>
            </div>

            <div class="clearfix"></div>
        </div>
    </div>
</script>
<script th:inline="javascript">
    var prefix = ctx + "publish/report"
    $("#form-report-add").validate({
        focusCleanup: true
    });

    /*上传参数配置 name 属性值必须为file*/
    var fileConfig = {
        uploadUrl: '/common/upload',
        maxFileSize: 30000,
        browseClass: 'btn btn-primary',
        dropZoneTitle: "拖拽文件到这里",
    }
    /*循环加载页面上传组件*/
    $.each($(".file-upload"), function () {
        var nodeId = $(this).attr('id');
        $.common.uploadFileInput(fileConfig, $(this), "input[name='" + nodeId + "']");
    });

    /*高拍仪调用*/
    function photograph(parameter) {
        $.modal.open("拍照", ctx + "publish/identsample/indexOne?parameter=" + parameter, 1200);
    }
    /*高拍仪回调*/
    function photo(_base64, _parameter, arr) {
        console.log(_parameter);
        $.operate.post('/common/uploadBase64',
            {"base64": _base64},
            function (result) {
                if (result.code == web_status.SUCCESS) {
                    if ($("input[name='" + _parameter + "']").val() == null || $("input[name='" + _parameter + "']").val() == "") {
                        $("input[name='" + _parameter + "']").val(result.fileName);
                    } else {
                        $("input[name='" + _parameter + "']").val($("input[name='" + _parameter + "']").val() + ',' + result.fileName);
                    }
                    var id = new Date().getTime();
                    var title = result.fileName.substring(result.fileName.lastIndexOf("/") + 1);
                    var data = {
                        src: result.fileName,
                        arr: '0',
                        title: title,
                        id: id,
                    };

                    // 将数据放入模板中
                    var res = template("template", data);
                    $("input[name='" + _parameter + "']").next().find(".file-drop-zone-title").remove();
                    // 将模板放入页面中
                    $("input[name='" + _parameter + "']").next().find(".file-preview-thumbnails").append(res);
                    $("#" + _parameter).fileinput('_initFileActions');
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        );

    }

    /*重新加载上传组件*/
    function reloadFileInput(_parameter) {
        var fileConfig = {
            uploadUrl: '/common/upload',
            maxFileSize: 30000,
            browseClass: 'btn btn-primary',
            dropZoneTitle: "拖拽文件到这里",
            showBrowse : true,
        }
        $.common.uploadFileInput(fileConfig, ("#" + _parameter), 'input[name="' + _parameter + '"]');
    }

    function previewHandle(fileDOM) {
        console.log(fileDOM);
        var file = fileDOM.files[0], // 获取文件
            imageType = /^image\//,
            reader = ""; // 文件是否为图片
        console.log(file);
        alert(JSON.stringify(file));F
        if (!imageType.test(file.type)) {
            alert("请选择图片！");
            return;
        } // 判断是否支持 FileReader
        if (window.FileReader) {
            reader = new FileReader();
        } // IE9及以下不支持 FileReader
        else {
            alert("您的浏览器不支持图片预览功能，如需该功能请升级您的浏览器！");
            return;
        } // 读取完成
        reader.onload = function(event) {
            // 获取图片DOM
            var img = document.getElementById("preview-img"); // 图片路径设置为读取的图片
            img.src = event.target.result;
        };
        reader.readAsDataURL(file);
    }

    function submitHandler() {
        console.log($("#lawId").val());
        if ($.validate.form()) {
            $.operate.saveTab(prefix + "/add", $('#form-report-add').serialize());
        }
    }

    function selectAuditor() {
        $.modal.open("选择审核人员", "/system/user/userSelect");
    }

    function selectReportToRegister() {
        $.modal.open("关联案件", "/publish/register/registerRadio");
    }

    $("#appraCon").change(function () {
        $("#samples").empty();
    });

    function selectReportToSample() {
        var _flag = $("#appraCon").val();
        var _appraCon;
        if(_flag=="正式出版物" || _flag=="其他" ){
            _appraCon=true;

        }else if(_flag=="非法出版物"){
            _appraCon=false;
        }
        var register = $("#registerId").val();
        if (register == null || register.length == 0) {
            $.modal.alertWarning("请选择案件");
        } else {
            $.modal.open("关联样本", "/publish/identsample/identsampleCheck?registerId=" + register+"&appraCon=" +_appraCon+"&sampleId="+sampleId);
        }
    }

    $("input[name='acceptTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });


    $(document).ready(function () {
        var ones = $("#appraCon").children('option:selected').val();
        $("#ChangeContent").empty();
        getChangeContent(ones)

        $("#appraCon").change(function () {
            var selected = $(this).children('option:selected').val();
            console.log(selected + "cccc")
            getChangeContent(selected);

        });

        $('.summernote').summernote({
            lang: 'zh-CN',
            callbacks: {
                onChange: function (contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function (files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function (error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });


    function getChangeContent(appraCon) {
        var samepleId = 'legal'
        if (appraCon == "正式出版物" || appraCon == "其他") {
            samepleId = 'legal';
        } else if (appraCon == "非法出版物") {
            samepleId = 'illegal';
        }
        //清空id
        sampleId=[];
        rowAll=[];
        $("#sampleIds").val('');
        var htmls = $(eval(samepleId)).html();
        $(".file-uploadAfter").fileinput("destroy");
        $("#ChangeContent").empty();
        $("#ChangeContent").append(htmls);
        if (appraCon == "非法出版物") {
            fileAfterInitial();
        }
    }

    // 上传 name 属性值必须为file
    if (1 == "非法出版物"){
        $(".file-uploadAfter").fileinput({
            uploadUrl: '/common/upload',
            showUpload: false,
            showRemove : true,
            maxFileSize: 30000,
            autoReplace: true,
            //allowedFileExtensions: ['jpg', 'png', 'bmp', 'jpeg'],
            showUpload: false, //是否显示上传按钮
            showCaption: true,//是否显示标题
            browseClass: "btn btn-primary",//按钮样式
            dropZoneTitle:"拖拽文件到这里",
            previewFileIcon: '<i class="fa fa-file-o text-info"></i>',
            preferIconicPreview: true,// 是否优先显示图标  false 即优先显示图片
            previewFileIconSettings: {
                'docx': '<i class="fa fa-file-word-o text-primary"></i>',
                'doc': '<i class="fa fa-file-word-o text-primary"></i>',
                'xlsx': '<i class="fa fa-file-excel-o text-success"></i>',
                'xls': '<i class="fa fa-file-excel-o text-success"></i>',
                'pptx': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
                'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
                'sql': '<i class="fa fa-file-word-o text-primary"></i>',
                'txt': '<i class="fa fa-file-text-o text-info"></i>',
                'rtf': '<i class="fa fa-file-text-o text-info"></i>',
            },
            // layoutTemplates: {
            //     actionDelete:'', //去除上传预览的缩略图中的删除图标
            //     actionUpload: '',//去除上传预览缩略图中的上传图片图标；
            //     //actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
            // },
        }).on('filebatchselected', function (event, data, id, index) {
            $(this).fileinput("upload");
        }).on('fileuploaded', function (event, data, previewId, index) {
            if($("input[name='" + event.currentTarget.id + "']").val()==""){
                $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName);
            }else {
                $("input[name='" + event.currentTarget.id + "']").val($("input[name='" + event.currentTarget.id + "']").val()+','+data.response.fileName);
            }
        }).on('filecleared', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        }).on('filesuccessremove', function (event, id, index) {//删除新上传的文件
            var nu=-1;
            var src = $("#"+id).attr("title");
            var fileUrlList = $("input[name='" + event.currentTarget.id + "']").val().split(",");
            if(src==""||src==null){
                src = $("#"+id+" img").attr("title");
                for(var i = 0 ;i<=fileUrlList.length-1;i++){
                    var src1 = fileUrlList[i].substring(fileUrlList[i].lastIndexOf("/")+1);
                    if(src1 == src ){
                        nu =i;
                    }
                }
            }else{
                for(var i = 0 ;i<=fileUrlList.length-1;i++){
                    var title1 = fileUrlList[i].substring(fileUrlList[i].lastIndexOf("/")+1);
                    if(title1 == src ){
                        nu =i;
                    }
                }
            }
            fileUrlList.splice(nu, 1);//去除下标为nu的值
            $("input[name='" + event.currentTarget.id + "']").val(fileUrlList);
        }).on('filedeleted', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        });

    }




    function fileShowInt() {
        $(".file-upload-show").each(function (i) {
            //debugger
            var vals = new Array()

            if ($("input[name='" + this.id + "']").val() != null) {
                var str = $("input[name='" + this.id + "']").val();
                var strs = new Array();
                strs = str.split(",");
                for (i = 0; i < strs.length; i++) {
                    vals[i] = ctx.slice(0, ctx.length - 1) + strs[i];
                }
            }
            //console.log("vals="+vals)

            $(this).fileinput({
                uploadUrl: '/common/upload',
                maxFileCount: 10,
                initialPreviewAsData: true,
                initialPreview: vals,
                showRemove: true,
                allowedPreviewTypes: ['image'],
                maxFileSize: 30000,
                autoReplace: true,
                allowedFileExtensions: ['jpg', 'png', 'bmp', 'jpeg'],
                showUpload: false, //是否显示上传按钮
                showCaption: false,//是否显示标题
                browseClass: "btn btn-primary",//按钮样式
                showBrowse:false,
                dropZoneTitle: " ",
                layoutTemplates: {
                    actionDelete:'', //去除上传预览的缩略图中的删除图标
                //     // actionUpload: '',//去除上传预览缩略图中的上传图片图标；
                //     //actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
                },
            }).on('filebatchselected', function (event, data, id, index) {
                // $(this).fileinput("upload");
            }).on('fileuploaded', function (event, data, previewId, index) {
                // data.response.url   data.response.fileName
                // debugger
                // $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName)
            }).on('filecleared', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            }).on('filesuccessremove', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            }).on('filedeleted', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            });

        })

    }
    // 设置审核人员
    function setUser(rows) {
        var _userId = [];
        var _userName = [];
        rows.forEach(function (item){
            _userId.push(item.userId)
            _userName.push(item.userName)
        })
        $('#auditorId').val(_userId.join(','));
        $('#auditor').val(_userName.join(','));

    }

    // 设置
    function setReport(rows) {
        var _sendUnit = [];
        var _documentNum = [];
        var _category = [];
        var _id = [];
        rows.forEach(function (item) {
            console.log(item.sendUnit)
            _id.push(item.id);
            _sendUnit.push(item.sendUnit);
            _documentNum.push(item.documentNum);
            _category.push(item.category);
        })


        $('#registerId').val(_id.join(','));
        $('#sendUnitId').val(_sendUnit.join(','));
        $('#documentNum').val(_documentNum.join(','));
        $('#category').val(_category.join(','));

    }

    // 设置
    function setLegal(rows) {
        var _title = [];
        var _id = [];
        rows.forEach(function (item) {
            _title.push(item.title);
            _id.push(item.id);
        })
        $('#by3').val(_title.join(','));
        $('#lawId').val(_id.join(','));
    }

    // 设置
    // function setReport(rows){
    //     var _sampleId=[];
    //     var _photo=[];
    //
    //     rows.forEach(function(item){
    //
    //         _sampleId.push(item.id);
    //         _photo.push(item.documentNum);
    //
    //     })
    //
    //
    //
    //     $('#documentNum').val(_sampleId.join(','));
    //     $('#category').val(_category.join(','));
    //
    // }


    var sampleData=[];
    var sampleId=[];
    var rowAll=[];
    var publishInfo = "";

    // 设置
    function setSamnples(rows) {
        var _sampleId = [];
        var _sampleName = [];
        var _publishInfo = [];
        var _publishInfoText = [];

        var i = 1;
        var samples = []
        var content = ""
        person = new Object();
        //debugger
        rows.forEach(function (item) {
            _sampleId.push(item.id);
            _sampleName.push(item.sampleName);
            if(item.publishInfo!=null&&item.publishInfo!=''){
                _publishInfo.push(item.publishInfo);
            }

            _publishInfoText.push(item.publishInfoText);
            var publishInfoText="";
            if (item.publishInfoText==null){
                publishInfoText=""
            }else{

                // publishInfoText=item.publishInfoText.replace(new RegExp("\r\n","gm"),"");
                publishInfoText= valueReplace(item.publishInfoText.replace(new RegExp("\r\n","gm"),""))
            }
            // sameplestring=sameplestring+'{"sampleName":"'+item.sampleName+'","publishInfo":"'+item.publishInfo+'"}'+',';
            var publishIndex = "imageShow" + i
            var fronCover="";
            fronCover=item.frontCover!=null?item.frontCover:"";

            publishInfo = item.publishInfo!=null?item.publishInfo:"";
            content = content + '{' +
                '"sampleName":"' + item.sampleName + '",' +
                '"fronCover":"' + fronCover + '",' +
                '"publishInfoText":"' +  publishInfoText+ '"' +

                '},';
        })
        content = content.substring(0, content.length - 1);       //将字符串转成JSON对象
        var data = '{' +
            '"samples":[' +
            content +
            ']' +
            '}';



        sampleData = JSON.parse(data);
        getSampleInfo(JSON.parse(data))
        sampleId = _sampleId;
        rowAll=rows;

        $('#sampleIds').val(_sampleId.join(','));

        // 初始化相应图片
         fileShowInt()

        if($("#appraCon").children('option:selected').val()=="非法出版物"&&_publishInfo.length!=0){//选择非法出版物-将样本的版权信息放入报告的样本版权记录中
            // var str1 = new Array();
            // var p = _publishInfo.toString().split(",");
            // for (i = 0; i < p.length; i++) {
            //     str1[i] = ctx.slice(0, ctx.length - 1) + p[i];
            // }
            var fileConfig = {
                uploadUrl: '/common/upload',
                maxFileSize: 30000,
                browseClass: 'btn btn-primary',
                dropZoneTitle: "拖拽文件到这里",
            }
            var pub = [];
            if($("input[name='copyrightRecord']").val()!=''){
                pub = $("input[name='copyrightRecord']").val().toString().split(',');//文件框所有文件的值
            }
            $("#copyrightRecord").fileinput('destroy');
            var arr = new Array();
            var p = publishInfo.toString().split(",");//样本版权记录的值
            for (i = 0; i < p.length; i++) {
                arr[i] = ctx.slice(0, ctx.length - 1) + p[i];
            }
            //删除关联样本时，过滤属于样本版权记录的图片，保留文件框单独上传的图
            p.forEach((item)=>{
                pub = pub.filter((currentValue)=>{
                    return currentValue !== item;
                })
            })
            if(pub.length>0){
                $("input[name='copyrightRecord']").val(pub.concat(p).toString());
            }else {
                $("input[name='copyrightRecord']").val(p.toString());
            }
            //$(".file-uploadAfter").fileinput({initialPreview: arr})
            $.common.uploadFileInput(fileConfig, $("#copyrightRecord"), "input[name='copyrightRecord']");

            // for (i = 0; i < str1.length; i++) {
            //     console.log("str1="+str1[i])
            //     var id = new Date().getTime();
            //     var title = str1[i].substring(str1[i].lastIndexOf("/") + 1);
            //     var data = {
            //         src: str1[i],
            //         arr: '0',
            //         title: title,
            //         id: id,
            //     };
            //     var _parameter='copyrightRecord';
            //     // 将数据放入模板中
            //     var res = template("template1", data);
            //     $("input[name='" + _parameter + "']").next().find(".file-drop-zone-title").remove();
            //     // 将模板放入页面中
            //     $("input[name='" + _parameter + "']").next().find(".file-preview-thumbnails").append(res);
            //     $("#" + _parameter).fileinput('_initFileActions');
            //
            //     //将获取的路径放入隐藏input中保存至后台
            //     if($("input[name='" + _parameter + "']").val()==""){
            //         $("input[name='" + _parameter + "']").val(str1[i]);
            //     }else {
            //         $("input[name='" + _parameter + "']").val($("input[name='" + _parameter + "']").val()+','+str1[i]);
            //     }
            // }
        }

    }

    // function showImg() {
    //     var p = $("#show").parents(".file-preview-frame");
    //     console.log(p.children(".file-preview-image").attr("src"));
    // }

    function valueReplace(v) {
        if (v.indexOf("\"") != -1) {
            v = v.toString().replace(new RegExp('(["\"])', 'g'), "\\\"");
        }
        else if (v.indexOf("\\") != -1)
            v = v.toString().replace(new RegExp("([\\\\])", 'g'), "\\\\");
        return v;
    }

    function showSlelect(){
        $.modal.open("法律条文", "/publish/provisions/provisionsRadio");
    }

    function getSampleInfo(data) {
        var str = template("samplesTemplate", data); //第一个参数是模板的id，第二个参数是data数据

        $("#samples").empty()
        $("#samples").append(str);
        //fileShowInt();

    }

    //删除关联的样本
    function delSample(i) {
        // console.log(i)
        if(i==0){
            sampleData.samples.splice(0,1);
            sampleId.splice(0,1);
            rowAll.splice(0,1);
        }else{
            sampleData.samples.splice(i,i);
            sampleId.splice(i,i);
            rowAll.splice(i,i);
        }
        $('#sampleIds').val(sampleId.join(','));
        getSampleInfo(sampleData)

        if($("#appraCon").children('option:selected').val()=="非法出版物"){
            var fileConfig = {
                uploadUrl: '/common/upload',
                maxFileSize: 30000,
                browseClass: 'btn btn-primary',
                dropZoneTitle: "拖拽文件到这里",
            }
            var pub = $("input[name='copyrightRecord']").val().toString().split(',');//文件框所有文件的值
            $("#copyrightRecord").fileinput('destroy');
            var arr = new Array();
            var p = publishInfo.toString().split(",");//样本版权记录的值
            for (i = 0; i < p.length; i++) {
                arr[i] = ctx.slice(0, ctx.length - 1) + p[i];
            }
            //删除关联样本时，过滤属于样本版权记录的图片，保留文件框单独上传的图
            p.forEach((item)=>{
                pub = pub.filter((currentValue)=>{
                    return currentValue !== item;
                })
            })
            $("input[name='copyrightRecord']").val(pub.toString());
            $.common.uploadFileInput(fileConfig, $("#copyrightRecord"), "input[name='copyrightRecord']");
        }

    }

    
    
    function  fileAfterInitial() {
        console.log("!231");
        // var fileConfig = {
        //     uploadUrl: '/common/upload',
        //     maxFileSize: 30000,
        //     browseClass: 'btn btn-primary',
        //     dropZoneTitle: "拖拽文件到这里",
        // }
        // $.common.uploadFileInput(fileConfig, $("#copyrightRecord"), "input[name='copyrightRecord']");
        // 上传 name 属性值必须为file
        $(".file-uploadAfter").fileinput({
            uploadUrl: '/common/upload',
            showUpload: false,
            showRemove : true,
            maxFileSize: 30000,
            autoReplace: true,
            //allowedFileExtensions: ['jpg', 'png', 'bmp', 'jpeg'],
            showUpload: false, //是否显示上传按钮
            showCaption: true,//是否显示标题
            browseClass: "btn btn-primary",//按钮样式
            dropZoneTitle:"拖拽文件到这里",
            previewFileIcon: '<i class="fa fa-file-o text-info"></i>',
            preferIconicPreview: true,// 是否优先显示图标  false 即优先显示图片
            previewFileIconSettings: {
                'docx': '<i class="fa fa-file-word-o text-primary"></i>',
                'doc': '<i class="fa fa-file-word-o text-primary"></i>',
                'xlsx': '<i class="fa fa-file-excel-o text-success"></i>',
                'xls': '<i class="fa fa-file-excel-o text-success"></i>',
                'pptx': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
                'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
                'sql': '<i class="fa fa-file-word-o text-primary"></i>',
                'txt': '<i class="fa fa-file-text-o text-info"></i>',
                'rtf': '<i class="fa fa-file-text-o text-info"></i>',
            },
            // layoutTemplates: {
            //     actionDelete:'', //去除上传预览的缩略图中的删除图标
            //     actionUpload: '',//去除上传预览缩略图中的上传图片图标；
            //     //actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
            // },
        }).on('filebatchselected', function (event, data, id, index) {
            $(this).fileinput("upload");
        }).on('fileuploaded', function (event, data, previewId, index) {
            // if($("input[name='" + event.currentTarget.id + "']").val()==""){
            //     $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName);
            // }else {
            //     $("input[name='" + event.currentTarget.id + "']").val($("input[name='" + event.currentTarget.id + "']").val()+','+data.response.fileName);
            // }
            var $control=$("input[name='" + event.currentTarget.id + "']");
            if ($control.val() == "") {
                $control.val(data.response.fileName);
            } else {
                var controlVal=$control.val()+ ',' + data.response.fileName;
                $control.val(controlVal);
            }
        }).on('filecleared', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        }).on('filesuccessremove', function (event, id, index) {//删除新上传的文件
            var nu=-1;
            var src = $("#"+id).attr("title");
            var fileUrlList = $("input[name='" + event.currentTarget.id + "']").val().split(",");
            if(src==""||src==null){
                src = $("#"+id+" img").attr("title");
                for(var i = 0 ;i<=fileUrlList.length-1;i++){
                    var src1 = fileUrlList[i].substring(fileUrlList[i].lastIndexOf("/")+1);
                    if(src1 == src ){
                        nu =i;
                    }
                }
            }else{
                for(var i = 0 ;i<=fileUrlList.length-1;i++){
                    var title1 = fileUrlList[i].substring(fileUrlList[i].lastIndexOf("/")+1);
                    if(title1 == src ){
                        nu =i;
                    }
                }
            }
            fileUrlList.splice(nu, 1);//去除下标为nu的值
            $("input[name='" + event.currentTarget.id + "']").val(fileUrlList);
        }).on('filedeleted', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        });

    }
    //获取子页面传过来的值
    function rows() {
        return rowAll;
    }
</script>
</body>
</html>
<!--数据模板-->
<script type="text/html" id="samplesTemplate">
    {{each samples as sample i}}
    <div class="row">

        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label ">样本名称：</label>
                <div class="col-sm-8">
                    <input name="expertName" value="{{sample.sampleName}}" readonly class="form-control" type="text">
                </div>
            </div>
        </div>

        <div class="col-sm-12" style="position: absolute;left: 33.3%;">
            <div class="form-group">
                <label class="col-sm-2 control-label"></label>
                <div class="col-sm-10">
                    <button type="button" class="btn btn-w-m btn-danger" onclick="delSample('{{i}}')">
                        <i class="fa fa-remove"></i>删除
                    </button>
                </div>
            </div>
        </div>

    </div>
    <div class="row">

        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label ">封面：</label>
                <input type="hidden" name="imageShow{{i}}" value="{{sample.fronCover}}">
                <div class="col-sm-8">

                    <div class="file-loading">
                        <input id="imageShow{{i}}"   class="form-control file-upload-show  hidden" multiple
                                  type="file">
                </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <div class="col-sm-12">
                    <input type="hidden" name="publishInfo" value="{{sample.publishInfo}}">
                        <textarea id="ocr{{i}}" readonly style="background-color: white"  rows="10" class="form-control" placeholder=""
                        >{{sample.publishInfoText}}</textarea>
                </div>
            </div>
        </div>

    </div>
    {{/each}}
</script>
<div class="hidden">
    <!--    合法-->
    <div id="legal">
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">鉴定内容：</label>
                    <div class="col-sm-10">
                        <textarea name="identiContent" maxlength="500" class="form-control" placeholder="输入鉴定内容"
                                  rows="5" required></textarea>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <!--    非法-->
    <div id="illegal">
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">简要案情：</label>
                    <div class="col-sm-8">
                        <input name="briefCase" class="form-control" type="text" >
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label is-required">鉴定内容：</label>
                    <div class="col-sm-10">
                        <textarea name="identiContent" maxlength="500" class="form-control" placeholder="输入鉴定内容"
                                  rows="5" required></textarea>
                    </div>
                </div>
            </div>
        </div>


<!--        <div class="row">-->

<!--            <div class="col-sm-6">-->
<!--                <div class="form-group">-->
<!--                    <label class="col-sm-4 control-label ">样本版权记录：</label>-->
<!--                    <div class="col-sm-8">-->
<!--                        <input name="copyrightRecord" class="form-control" type="text" >-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
<!--            -->
<!--        </div>-->

        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">样本版权记录：</label>

                    <div class="col-sm-10">
                        <!--             type="hidden"  class="myhide"          width设置为0，高度设置为0.5px-->
                        <input name="copyrightRecordEx" class="form-control" type="text" value="见附件">
                        <input name="copyrightRecord"  style="visibility: hidden;" id="inputCopyrightRecord">
                        <div class="file-loading">
                            <input class="form-control file-uploadAfter" multiple id="copyrightRecord" name="file" type="file" >
                        </div>

                    </div>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-10">
                        <button type="button" class="btn btn-w-m btn-warning" onclick="photograph('copyrightRecord')">
                            <i class="fa fa-check"></i>拍照
                        </button>
                    </div>
                </div>
            </div>
        </div>       
        



        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">鉴定情况：</label>
                    <div class="col-sm-10">
                        <textarea name="identiSituation" maxlength="500" class="form-control" placeholder="输入鉴定情况"
                                  rows="5" ></textarea>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">法律条文：</label>
                    <div class="col-sm-8">
                        <input id="by3" name="by3" readonly placeholder="请选择法律条文" onclick="showSlelect()"
                               class="form-control" type="text" required >
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <div class="col-sm-8">
                        <input id="lawId" name="lawId" class="hidden" type="text" required >
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>